#include "stm32f10x.h"                  // Device header

int32_t MyDMA_Size = 0; 

//source destination
//param 数组的首元素地址并转为uint32_t
void MyDMA_Init(uint32_t address_dst, int32_t size)
{
    MyDMA_Size = size;
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    DMA_InitTypeDef DMA_InitStruct;
    DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;                 //取出ADC——DR的地址

    DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //需要传输的数据的大小 这个是uint8_t
    DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;         //地址不自增，因只读取DR的值
    DMA_InitStruct.DMA_MemoryBaseAddr = address_dst;                     //destination
    DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;         //放置的数据的大小（一般和传输数据的大小相同，大了高位补0，小了只取低位）
    DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;                 //indedx 自增
    DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;                      //choose if src -> dst or dst -> src
    DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;                            //选择硬件触发还是软件触发
    DMA_InitStruct.DMA_BufferSize = MyDMA_Size;                          //计数寄存器
    DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;      
    DMA_InitStruct.DMA_Priority = DMA_Priority_High;    
    DMA_Init(DMA1_Channel1, &DMA_InitStruct);                            //因为是软件出发，通道可以自己选择
    
    DMA_Cmd(DMA1_Channel1, ENABLE);                                     //Disable 时才能给计数器赋值

}
